#region License

// This file is part of Grawlix.
// 
// Grawlix is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
// Grawlix is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// License along with Grawlix.  If not, see
// <http://www.gnu.org/licenses/>.

#endregion

using System;
using System.Collections.Generic;

namespace Grawlix.Services
{
	/// <summary>
	/// A message with a specified expiration.
	/// </summary>
	internal struct TimedMessage
	{
		/// <summary>
		/// The message to run.
		/// </summary>
		private Message _message;

		/// <summary>
		/// The time after which to expire.
		/// </summary>
		private TimeSpan _time;

		/// <summary>
		/// Gets or sets the message.
		/// </summary>
		/// <value>The message.</value>
		public Message Message
		{
			get { return _message; }
			set { _message = value; }
		}

		/// <summary>
		/// Gets or sets the time.
		/// </summary>
		/// <value>The time.</value>
		public TimeSpan Time
		{
			get { return _time; }
			set { _time = value; }
		}
	}

	/// <summary>
	/// A comparison object for comparing timed messages by time.
	/// </summary>
	internal class TimedMessageTimeComparer :
		IComparer<TimedMessage>
	{
		/// <summary>
		/// Compares two objects and returns a value indicating whether
		/// one is less than, equal to, or greater than the other.
		/// </summary>
		/// <param name="x">The first object to compare.</param>
		/// <param name="y">The second object to compare.</param>
		/// <returns>
		/// Value Condition Less than zero
		/// <paramref name="x"/> is less than <paramref name="y"/>.
		/// Zero
		/// <paramref name="x"/> equals <paramref name="y"/>. Greater
		/// than zero
		/// <paramref name="x"/> is greater than <paramref name="y"/>.
		/// </returns>
		public int Compare(TimedMessage x, TimedMessage y)
		{
			return x.Time.CompareTo(y.Time);
		}
	}
}